<template>
    <div class="wrapper">
        <!-- banner图默认为显示最后一张，解决：v-if="list.length"，当list为空数组时，v-if的值是false,swiper不会被创建 -->
        <!-- <swiper :options="swiperOption" v-if="list.length"> -->
        <swiper :options="swiperOption" v-if="showSwiper">    
            <!-- slides -->
            <swiper-slide v-for="item in list" :key="item.id">
                <img class="swiper-img" :src="item.imgUrl" alt="">
            </swiper-slide>
            <!-- Optional controls -->
            <div class="swiper-pagination"  slot="pagination"></div>
        </swiper>
    </div>
</template>

<script>
export default {
    name:'HomeSwiper',
    // props:{
    //     list:Array
    // },
    props:['list'],
    data () {
        return {
            swiperOption: {
                pagination:'.swiper-pagination',
                loop: true  //图片循环
            }
        }
    },
    computed:{
        showSwiper() {
            return this.list.length
        }
    }
}
</script>

<style lang="stylus" scoped>
    // 样式穿透，wrapper下面所有子组件的样式，不受scoped的限制
    .wrapper >>> .swiper-pagination-bullet-active
        background-color: #fff
    .wrapper
        width: 100%
        height: 0
        overflow: hidden
        padding-bottom: 31.25%
        background-color: #eee
        .swiper-img
            width: 100%
        
</style>